package com.kehutong.session.entity;

import org.coraframework.orm.Entity;
import org.coraframework.orm.annotation.Column;
import org.coraframework.orm.annotation.Table;
import org.coraframework.util.Objects;
import org.coraframework.util.time.TimeUtil;

import com.kehutong.common.enums.UserType;

/**
 * 用户token
 *
 * @Author: liuzhen (liuxing521a@163.com)
 * @Date: 20/4/16 上午9:03
 */
@Table("t_session")
public class Session extends Entity {
	
	private static final long SESSION_EXPIRED_TIME = 30*TimeUtil.MILLIS_PER_MINUTE;
	
	private static final long serialVersionUID = 2180436071806536306L;

	protected Session(String id) {
		super(id);
	}
	
	@Column(comment="企业编号")
    private String companyNo;
	
	@Column(comment="企业名称")
    private String companyName;
	
	@Column(comment="企业id")
    private String corpid;

	@Column(comment="登陆应用id")
    private String suiteId;

	@Column(comment="用户编号")
    private String uuid;

	@Column(length=64, comment="用户id")
	private String userId;

	@Column(length=64, comment="用户昵称")
    private String username;
	
	@Column(comment="手机号")
    private String mobile;

	@Column(length=255, comment="头像")
    private String headUrl;

	@Column(comment="登陆类型")
    private UserType userType;
	
	@Column(dbType="TEXT",comment="当前部门")
	private String department;
	
	@Column(dbType="TEXT", comment="用户角色")
	private String roles;
	
	@Column(dbType="TEXT", comment="客户权限")
	private String permissions;
	
	@Column(comment="已过期删除")
	private boolean deleted;

	@Column(comment = "用户创建时间")
	private long userCreateTime;

	@Column(length = 555,comment = "拓展内容")
	private String extContent;

	@Column(comment="客户中台-通讯录查看状态")
	private boolean newsletterState;

	@Column(comment="客户中台-首页统计查看状态")
	private boolean frontPageState;

	@Column(comment="客户中台-我的企业查看状态")
	private boolean businessState;

	@Column(comment="客户中台-设置查看状态")
	private boolean settingState;

	@Column(comment="上次提醒时间")
	private Long remindTime;

	/** 版本*/
	@Column(comment="版本")
	private String version;
	

	public String getCompanyNo() {
		return companyNo;
	}

	public void setCompanyNo(String companyNo) {
		this.companyNo = companyNo;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getCorpid() {
		return corpid;
	}

	public void setCorpid(String corpid) {
		this.corpid = corpid;
	}

	public String getSuiteId() {
		return suiteId;
	}

	public void setSuiteId(String suiteId) {
		this.suiteId = suiteId;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getHeadUrl() {
		return headUrl;
	}

	public void setHeadUrl(String headUrl) {
		this.headUrl = headUrl;
	}

	public UserType getUserType() {
		return userType;
	}

	public void setUserType(UserType userType) {
		this.userType = userType;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}
	
	public String getRoles() {
		return roles;
	}

	public void setRoles(String roles) {
		this.roles = roles;
	}

	public String getPermissions() {
		return permissions;
	}

	public void setPermissions(String permissions) {
		this.permissions = permissions;
	}

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public boolean isExpired() {
		if (Objects.isNull(getUpdateTime())) {
			return true;
		}
		
		return getUpdateTime().getTime() + SESSION_EXPIRED_TIME < TimeUtil.timeMillis();
	}

	public String getExtContent() {
		return extContent;
	}

	public void setExtContent(String extContent) {
		this.extContent = extContent;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public long getUserCreateTime() {
		return userCreateTime;
	}

	public void setUserCreateTime(long userCreateTime) {
		this.userCreateTime = userCreateTime;
	}

	public boolean isNewsletterState() {
		return newsletterState;
	}

	public void setNewsletterState(boolean newsletterState) {
		this.newsletterState = newsletterState;
	}

	public boolean isFrontPageState() {
		return frontPageState;
	}

	public void setFrontPageState(boolean frontPageState) {
		this.frontPageState = frontPageState;
	}

	public boolean isBusinessState() {
		return businessState;
	}

	public void setBusinessState(boolean businessState) {
		this.businessState = businessState;
	}

	public boolean isSettingState() {
		return settingState;
	}

	public void setSettingState(boolean settingState) {
		this.settingState = settingState;
	}

	public Long getRemindTime() {
		return remindTime;
	}

	public void setRemindTime(Long remindTime) {
		this.remindTime = remindTime;
	}
}
